﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TodayWhoModel;

namespace TodayWho.adm
{
    public partial class preview : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string userName = Request.QueryString["u"];
            if (!string.IsNullOrEmpty(userName))
            {
                GetUsersInfo(userName);
            }
        }
        private void GetUsersInfo(string userName)
        {
            UserModel user = new UserModel();
            user.UserName = userName;
            user.RetrieveUserInfoWithUserNameForAccount();
            FillInfo(user);

        }
        private void FillInfo(UserModel user)
        {
            if (user.NameSurname == null)
            {
                Response.Redirect("notcontrolled.aspx");
            }
            else
            {
                hdnUserId.Value = user.UserId.ToString();
                imgUserPhoto.Src = user.PhotoUrl1;
                lblUserNameSurname.Text = user.NameSurname;
                lblUserShortDesc.Text = user.ShortDesc;

                if (!string.IsNullOrEmpty(user.Facebook))
                {
                    hypFacebook.HRef = user.Facebook;
                    hypFacebook.Visible = true;
                }
                if (!string.IsNullOrEmpty(user.Twitter))
                {
                    hypTwitter.HRef = user.Twitter;
                    hypTwitter.Visible = true;
                }
                if (!string.IsNullOrEmpty(user.Blogger))
                {
                    hypBlogger.HRef = user.Blogger;
                    hypBlogger.Visible = true;
                }
                if (!string.IsNullOrEmpty(user.Wordpress))
                {
                    hypWordpress.HRef = user.Wordpress;
                    hypWordpress.Visible = true;
                }
                if (!string.IsNullOrEmpty(user.Linkedin))
                {
                    hypLinkedin.HRef = user.Linkedin;
                    hypLinkedin.Visible = true;
                }
                if (!string.IsNullOrEmpty(user.Tumblr))
                {
                    hypTumblr.HRef = user.Tumblr;
                    hypTumblr.Visible = true;
                }
                if (!string.IsNullOrEmpty(user.Formspring))
                {
                    hypFormspring.HRef = user.Formspring;
                    hypFormspring.Visible = true;
                }
                if (!string.IsNullOrEmpty(user.Stumbleupon))
                {
                    hypStumbleupon.HRef = user.Stumbleupon;
                    hypStumbleupon.Visible = true;
                }
                if (!string.IsNullOrEmpty(user.Flickr))
                {
                    hypFlickr.HRef = user.Flickr;
                    hypFlickr.Visible = true;
                }
                if (!string.IsNullOrEmpty(user.Picasa))
                {
                    hypPicasa.HRef = user.Picasa;
                    hypPicasa.Visible = true;
                }
                if (!string.IsNullOrEmpty(user.Myspace))
                {
                    hypMyspace.HRef = user.Myspace;
                    hypMyspace.Visible = true;
                }
                if (!string.IsNullOrEmpty(user.Lastfm))
                {
                    hypLastfm.HRef = user.Lastfm;
                    hypLastfm.Visible = true;
                }
                if (!string.IsNullOrEmpty(user.Youtube))
                {
                    hypYoutube.HRef = user.Youtube;
                    hypYoutube.Visible = true;
                }
                if (!string.IsNullOrEmpty(user.Foursquare))
                {
                    hypFoursquare.HRef = user.Foursquare;
                    hypFoursquare.Visible = true;
                }
                if (!string.IsNullOrEmpty(user.Website1))
                {
                    hypWebsite1.HRef = user.Website1;
                    lblWebsite1.Text = user.Website1;
                    hypWebsite1.Visible = true;
                }
                if (!string.IsNullOrEmpty(user.Website2))
                {
                    hypWebsite2.HRef = user.Website2;
                    lblWebsite2.Text = user.Website2;
                    hypWebsite2.Visible = true;
                }
                if (!string.IsNullOrEmpty(user.Website3))
                {
                    hypWebsite3.HRef = user.Website3;
                    lblWebsite3.Text = user.Website3;
                    hypWebsite3.Visible = true;
                }
            }
        }

        protected void btnAppropriate_OnClick(object sender, EventArgs e)
        {
            UserDisplayModel userDisplay = new UserDisplayModel();
            userDisplay.UserId = Convert.ToInt32(hdnUserId.Value);
            userDisplay.IsAppropriate=true;
            userDisplay.IsControlled = true;
            userDisplay.UpdateIsAppropriate();
            userDisplay.UpdateIsControlled();
            Response.Redirect("notcontrolled.aspx");
            
        }
        protected void btnInappropriate_OnClick(object sender, EventArgs e)
        {
            UserDisplayModel userDisplay = new UserDisplayModel();
            userDisplay.UserId = Convert.ToInt32(hdnUserId.Value);
            userDisplay.IsAppropriate = false;
            userDisplay.IsControlled = true;
            userDisplay.UpdateIsAppropriate();
            userDisplay.UpdateIsControlled();
            Response.Redirect("notcontrolled.aspx");
        }
    }
}